package com.lsy.clearssm.controller;

import com.lsy.clearssm.common.JsonResult;
import com.lsy.clearssm.pojo.User;
import com.lsy.clearssm.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author LSY
 * @Date 2021/10/22 11:32
 * @Version 1.0
 **/
@CrossOrigin
@RequestMapping(value = "/user", method = RequestMethod.POST)
@RestController  // ResponseBody + Controller
@Api(value = "用户操作接口")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/findUserById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, paramType = "Long")
    })
    public User findUserById(@RequestParam("uid") Long id) {
        return userService.findUserById(id);
    }

    @RequestMapping("/delUserByIds")
    public Map<String, Object> delUserByIds(@RequestBody Map<String, Long> ids) {
        List<Long> list = new ArrayList<>();
        for (Map.Entry<String, Long> id : ids.entrySet()) {
            list.add(id.getValue());
        }
        userService.delUserByIds(list);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("2000");
        jsonResult.setMsg("删除成功");
        return jsonResult.getMap();
    }
}
